from django.db import models


# Create your models here.


class Category(models.Model):
    name = models.CharField('分类名', max_length=32)
    pic = models.ImageField(upload_to="static/pic", null=True)

    class Meta:
        db_table = 'category'
        verbose_name = '分类名'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Goods(models.Model):
    ''' 商品名 价格  首图  简介  内容  单位  分类  库存'''
    name = models.CharField("商品名", max_length=32)
    price = models.DecimalField("商品价格", max_digits=8, decimal_places=2)
    img = models.ImageField("首图", upload_to="static/pic")
    desc = models.CharField("简介", max_length=200)
    content = models.TextField(verbose_name="详情")
    unit = models.CharField("单位", max_length=20)
    store = models.IntegerField("库存", default=0)
    cate = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name="商品分类")

    class Meta:
        db_table = 'goods'
        verbose_name = "商品表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
